package com.morningstar.qs.api.basic.util;

import java.beans.PropertyDescriptor;
import org.apache.commons.beanutils.*;
import org.apache.log4j.Logger;


/**
 * @deprecated
 * @author dchen2
 *
 */
public class JavaBeanUtil {
	private final static Logger gLogger = Logger.getLogger(JavaBeanUtil.class);
	
	private JavaBeanUtil(){};
	
	/**
	 * return a string printing all field values of the bean
	 * @param bean
	 * @return
	 */
	@Deprecated
	public static String getPrintString(Object bean) {
		
		if (bean == null){
			return "null";
		}
		
		PropertyDescriptor[] pd =
			PropertyUtils.getPropertyDescriptors(bean.getClass());

		String printString = "";
		for (int i = 0; i < pd.length; i++) {
			try {
				printString =
					printString
						+ pd[i].getName()
						+ StringUtil.getSpacebar(15-pd[i].getName().length())
						+ " = \""
						+ PropertyUtils.getSimpleProperty(bean, pd[i].getName())
						+ "\"\n";
			} catch (Exception e) {
				gLogger.error("PropertyUtils.getSimpleProperty() exception! Property=" + pd[i].getName(), e);
			}
		}
		return printString;
	}

}
